import os
import pymongo

database = 'novel'
export_path = './novel'

conn = pymongo.MongoClient(host='10.0.0.10', port=27017)
db = conn[database]
collections = db.list_collection_names()
for collection in list(collections):
    print(collection)
    print("mongoexport -h 10.0.0.10 -d {} -c {}  --fields '_id,内容'  --out {}/{}.json".format(database,
                                                                                                           collection,
                                                                                                           export_path,
                                                                                                           collection))
    os.system("mongoexport -h 10.0.0.10 -d {} -c {}  --fields '_id,内容'  --out {}/{}.json".format(database,
                                                                                                           collection,
                                                                                                           export_path,
                                                                                                           collection))
